<?php
App::uses('AppController', 'Controller');

/**
*  
*/
class OsController extends AppController
{
	
	var $name = "Os";// ten cua Controller
    var $helpers = array('Paginator','Html');
    var $components = array('Session');
    var $paginate = array();
	public function beforeFilter() {
		parent::beforeFilter();
		//$this -> Auth -> allow();
	}

	/**
	* index method
	*/
	public function admin_index() {
		$this->loadModel('Os');
		$this->paginate = array(
                                'limit' => ITEM_PER_PAGE,
                                'order' => array('id' => 'asc'),
                             );
		
		$data = $this->paginate("Os");
        $this->set("data",$data);
	}

	public function admin_add() {
		$this->loadModel('Os');
		if ($this -> request -> is('post')) {
			$new = $this -> data;
			if ($this -> Os -> save($new)){
				$this->Session->setFlash('Thêm OS thành công');
				$this->redirect(array('action' => 'index'));
			}
			$this->set('errors', $this->Os->validationErrors);
		}
	}

	/**
	 * edit method
	 * param id integer , id of Slider
	 */
	public function admin_edit($id) {
		$this->loadModel('Os');
		$conditions = array("Os.id" => $id);
		$data = $this->Os->find('first', array('conditions' => $conditions));
		parent::createException($data['Os']);
		$this -> set("data", $data['Os']);
		$this -> set("id",$id);
		if ($this -> request -> is('post')) {
			$update = $this -> data;
			if($this -> Os -> save($update)){
				$this->Session->setFlash('Os được cập nhật');
				$this->redirect(array('action' => 'index'));
			}
			$this -> set('errors', $this -> Os -> validationErrors);
		}
	}
	/**
	 * delete method
	 * param id integer , id of Slider
	 */
	public function admin_delete($id) {
		$conditions = array("Os.id" => $id);
		$data = $this -> Os ->find('first', array('conditions' => $conditions));
		parent::createException($data['Os']);
		$data['Os']['deleted'] = 1;
		$this -> Os -> save($data['Os']);
		$this->Session->setFlash('Xóa thành công');
		return $this->redirect(array('controller' => 'Os', 'action' => 'index'));
	}
}
?>